function f = createSpindlesDensityFigure(intervalLength, spindles, plotTitle, titleText)

failIfFalse(isscalar(intervalLength), 'intervalLength should be scalar');
failIfFalse(isvector(spindles), 'spindles should be a vector');
failIfFalse(ischar(plotTitle), 'plotTitle should be a string');
failIfFalse(ischar(titleText), 'titleText should be a string');

x = [0 intervalLength];
y = [0 0];

tickSpace = round(intervalLength/10);
xTick = 0:tickSpace:intervalLength;
xLim = [0 intervalLength];

ax = axes('FontSize', 10, 'TickDir', 'out', 'XLim', xLim, 'XTick', xTick, 'YLim', [-1 1], 'YTickMode', 'manual');
xlabel('seconds', 'VerticalAlignment', 'top');

line(x, y, 'LineWidth', 0.5, 'Parent', ax);

for idx = 1:size(spindles, 2);    
  spindle = spindles(idx);
  failIfFalse((spindle < intervalLength) && (spindle >= 0), ...
  						'Spindle occurrences should be within the specified time interval'); 
  line([spindle spindle], [-0.2 0.2], 'LineWidth', 0.5, 'Color', 'red', 'Parent', ax);
end

title(plotTitle);
setAxesPosition(@gca, 1, 1);

setTitle(titleText);
set(gcf, 'Visible', 'off');

f = gcf;